<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <link rel="stylesheet" href="/static/admin/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form">

        <form id="DataForm" action="" method="POST" class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="itemTab">
                <ul class="layui-tab-title">
                    <li lay-id="itemTab_1" class="layui-this">基本信息</li>
                    <li lay-id="itemTab_2">sku</li>

                </ul>
              
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="info[title]" placeholder="请输入商品名称" autocomplete="off"
                                    class="layui-input" value="{$goods.title}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品编码</label>
                            <div class="layui-input-block">
                                <input type="text" name="info[code]" placeholder="请输入商品编码" autocomplete="off"
                                    class="layui-input" value="{$goods.code}">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">介绍</label>
                            <div class="layui-input-block">
                                <textarea name="info[introduce]" class="layui-textarea">{$goods.introduce}</textarea>
                            </div>
                        </div>
                    
                        <div class="layui-form-item">
                            <label class="layui-form-label">封面</label>
                            <div class="layui-input-block">
                                <input type="text" name="info[img]" id="img" autocomplete="off"
                                    class="layui-input layui-col-xs6" readonly value="{$goods.img}">
                                <div class="layuimini-upload-btn">
                                    <button type="button" class="layui-btn" id="upload_img"><i
                                            class="fa fa-upload"></i>
                                        上传图片</button>
                                </div>
                            </div>
                        </div>
                    
                        
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品分类</label>
                            <div class="layui-input-block">
                                <select name="info[cate_id]">
                                    <option value="0">请选择商品分类</option>
                                    {foreach $cate as $val}
                                    <optgroup label="{$val.title}">
                                        {foreach $val.list as $item}
                                        <option value="{$item.id}" {if $goods.cate_id== $item.id} selected{/if} >{$item.title}</option>
                                        {/foreach}
                                    </optgroup>
                                    {/foreach}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">排序</label>
                            <div class="layui-input-inline">
                                <input type="number" name="info[sort]" placeholder="请输入排序" autocomplete="off"
                                    class="layui-input" value="{$goods.sort}">
                            </div>
                            <div class="layui-form-mid layui-word-aux" style="color: red;">从大到小</div>

                            <label class="layui-form-label">虚拟销量</label>
                            <div class="layui-input-inline">
                                <input type="number" name="info[x_sales]" placeholder="请输入店铺电话" autocomplete="off"
                                    class="layui-input" value="{$goods.x_sales}">
                            </div>
                        </div>
                        <!-- <div class="layui-form-item">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <input type="checkbox" name="info[is_display]" value="{$goods.is_display}" lay-skin="switch" lay-text="上架|下架" lay-filter="is_display" {$goods.is_display == 1 ? 'checked' : '' }>
                            </div>
                            <div class="layui-form-mid layui-word-aux" style="color: red;">下架全部代理商 慎用</div>

                        
                        </div> -->

                        <div class="layui-form-item">
                            <label class="layui-form-label">商品图片</label>
                            <div class="layui-input-block">
                                <input autocomplete="off" class="layui-input layui-col-xs6"
                                    placeholder="请选择jpg,jpeg,png格式文件" readonly>
                                <div class="layuimini-upload-btn">
                                    <button type="button" class="layui-btn" id="upload_pic"><i
                                            class="fa fa-upload"></i>
                                        上传图片</button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-upload-list" id="img_list">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>预览</th>
                                        <th>大小</th>
                                        <th>状态</th>
                                        <th>操作<input type="radio" name="info[is_imgs_id]" value="-1" title="不选择封面" {if $goods['is_imgs_id'] == '-1'}checked{/if}></th>
                                    </tr>
                                </thead>
                                <tbody id="demoList" >
                                    {foreach $goods['imgs'] as $key=>$val}
                                        <tr id="upload-{$key}" class="delNodeTd">
                                            <td>
                                                <input type="hidden" name="info[imgs][]" value="{$val}"/>
                                                <img src="{$val}" style="width:28px;height:26px;"  onclick="look_pic('{$val}')"/>
                                            </td>
                                            <td></td>
                                            <td></td>
                                            <td>
                                                <button type="button" class="layui-btn layui-btn-xs layui-btn-danger pic-delete">删除</button>
                                                <input type="radio" name="info[is_imgs_id]" value="{$key}" title="封面"  {if $goods['is_imgs_id'] == $key}checked{/if}>
                                               
                                            </td>
                                        </tr>
                                        {/foreach}
                                </tbody>
                            </table>
                        </div>
                    
                      
                        <div class="layui-form-item">
                            <label class="layui-form-label">商品内容</label>
                            <div class="layui-input-block">
                                <input autocomplete="off" class="layui-input layui-col-xs6"
                                    placeholder="请选择jpg,jpeg,png格式文件" readonly>
                                <div class="layuimini-upload-btn">
                                    <button type="button" class="layui-btn" id="content_pic"><i
                                            class="fa fa-upload"></i>
                                        上传图片</button>
                                </div>
                            </div>
                        </div>
                        <div class="layui-upload-list" id="content_list" >
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>预览</th>
                                        <th>大小</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody id="contentList">
                                    {foreach $goods['content'] as $key=>$val}
                                    <tr id="upload-{$key}" class="delNodeTd">
                                        <td>
                                            <input type="hidden" name="info[content][]" value="{$val}" />
                                            <img src="{$val}" style="width:28px;height:26px;"  onclick="look_pic('{$val}')" />
                                        </td>
                                        <td></td>
                                        <td></td>
                                        <td><button type="button" class="layui-btn layui-btn-xs layui-btn-danger pic-delete">删除</button></td>
                                    </tr>
                                    {/foreach}
                                </tbody>
                            </table>
                        </div>
                       
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin:auto;text-align: center;">
                                <button type="button" class="upButton layui-btn layui-btn-primary"><i
                                        class="fa fa-level-up"></i> 上一步</button>
                                <button type="button" class="downButton layui-btn layui-btn-normal"><i
                                        class="fa fa-level-down"></i> 下一步</button>
                            </div>
                        </div>
                    </div>


                    <div class="layui-tab-item">


                        <div class="layui-form-item">
                            <!-- <label class="layui-form-label">商品SKU</label>
                            <div class="layui-input-inline" style="width: 120px;">
                                <button type="button" id="add_sku" class="layui-btn layui-btn-normal "><i
                                        class="fa fa-plus"></i>
                                    新建分组</button>
                                 
                            </div> -->
                            <div id="sku_key">
                                <div class="layui-form-item" id="sku_sku_key">
                                    <div  class="layui-input-inline" style="width: 100px; display: none;"> <input type="text" name="sku[1710438857134][name]"
                                            data-id="1710438857134" autocomplete="off" class="group layui-input" placeholder="例：颜色">
                                        <div class="layuimini-upload-btn delClassAttr" style="top:11px;right:8px;color:#C1C1C1; display: none;"><i
                                                class="fa fa-remove"></i></div>
                                    </div>
                                    <div class="layui-inline"> <label class="layui-form-label">属性规格</label>
                                        <div class="layui-input-inline" style="width: 100px;"> <input type="text" name="sku[1710438857134][value][]"
                                                autocomplete="off" class="attr layui-input" placeholder="例：黑色"> </div>
                                    </div>
                                   
                                </div>
                                <div class="layui-inline" id="button_1710438857134">
                                    <div class="layui-input-inline"> <button type="button" data-id="1710438857134"
                                            class="addSkuRow layui-btn layui-btn-normal"><i class="fa fa-plus"></i> 新增</button> </div>
                                </div>
                            </div>
                            <div class="layui-form-mid layui-word-aux">注意：SKU可以不设置。商品新增完成后，SKU将无法修改！</div>
                        </div>
                        <div id="sku_key"></div>
                        <div class="layui-upload-list">
                            <table class="layui-table">
                                <thead>
                                    <tr>
                                        <th>属性规格</th>
                                        <th class="batchSet" data-class="money_cost"
                                            style="color: #00C0F8;cursor: pointer;"><i class="fa fa-pencil"></i> 成本价格
                                        </th>
                                        <th class="batchSet" data-class="money"
                                            style="color: #00C0F8;cursor: pointer;"><i class="fa fa-pencil"></i>销售价格
                                        </th>
                                        <th style="width: 100px;text-align: center;">库存</th>
                                        <th style="width: 100px;text-align: center;">默认展示</th>
                                        <th style="width: 50px;text-align: center;">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {foreach $sku as $vo}
                                    <tr>
                                        <td>{$vo.sku_title}</td>
                                        <td>
                                            <input name="sku_data_update[{$vo['id']}][sku_title]" value="{$vo.sku_title}" type="hidden">
                                            <input name="sku_data_update[{$vo['id']}][id]" value="{$vo.id}" type="hidden">
                                            <input name="sku_data_update[{$vo['id']}][money_cost]" type="number" style="display: unset;width: 80px;" autocomplete="off"
                                                class="money_cost layui-input" value="{$vo['money_cost']}"> 元
                                        </td>
                                        <td>
                                            <input name="sku_data_update[{$vo['id']}][money]" type="number" style="display: unset;width: 80px;" autocomplete="off"
                                                class="money layui-input" value="{$vo['money']}"> 元
                                        </td>
                                        <td>
                                            <input name="sku_data_update[{$vo['id']}][stock]" type="number" style="display: unset;width: 80px;" autocomplete="off"
                                                class="stock layui-input" value="{$vo['stock']}">
                                        </td>
                                        <td style="text-align: center;"><input type="radio" name="is_default" value="{$vo['id']}" title="选择" checked></td>
                                        <td style="text-align: center;">
                                            <!-- <button type="button" class="layui-btn layui-btn-xs layui-btn-danger delRuleRow">删除</button> -->
                                        </td>
                                    </tr>
                                    {/foreach}
                                </tbody>
                                <tbody id="sku_data">
                                   
                                </tbody>
                            </table>
                        </div>


                        <div class="layui-form-item">
                            <input type="hidden" name="id" value="{$goods.id}">
                            <div class="layui-input-block" style="margin:auto;text-align: center;">
                                <button type="button" class="upButton layui-btn layui-btn-primary"><i
                                        class="fa fa-level-up"></i> 上一步</button>
                                <button id="saveButton" type="submit" class="layui-btn"><i class="fa fa-check"></i>
                                    提交</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </form>
    </div>
    <script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script src="/static/admin/lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <script src="/static/admin/js/jquery-ui.js"></script>
    <script src="/static/admin/sortable/Sortable.min.js"></script>
<script>
        //商品图片拖拽
        $("#demoList").sortable({
                axis: "y",  // y方向拖动
                containment: "parent",  // 约束范围为父元素内部
                cursor: "move",
                cursorAt: { left: 5 },
                // disabled: true,
                distance: 5,
                update: updateHandle
            });
            $("#contentList").sortable({
                axis: "y",  // y方向拖动
                containment: "parent",  // 约束范围为父元素内部
                cursor: "move",
                cursorAt: { left: 5 },
                // disabled: true,
                distance: 5,
                update: updateHandle
            });
            var arr = [];
            function updateHandle() {
                arr = [];
                Array.prototype.slice.call($('tr td')).forEach(function (element, index) {
                arr.push(element.dataset.id)
                });
              
            }
</script>
    <script>
        var look_pic;
        layui.use(['layer', 'form', 'laydate', 'element', 'upload','tableSelect','wangEditor'], function () {
            var member_level;
        
            var    tableSelect = layui.tableSelect;
            var $ = layui.$, layer = layui.layer, table = layui.table, element = layui.element, laydate = layui.laydate, form = layui.form, upload = layui.upload;
            var indexFrame = parent.layer.getFrameIndex(window.name); //获取窗口索引
            var wangEditor = layui.wangEditor;
        
            var loading_body = layer.open({ type: 3 });
         

            $.post("{:url('get_level')}", {},
                function (data, textStatus, jqXHR) {
                    member_level = data.data;
                    // create_sku();
                    layer.close(loading_body);
                }
            );

          
        
        

            $("#closeButton").on('click', function () {
                parent.layer.close(indexFrame);
            })

            // 分步表单下一步
            $(".downButton").on('click', function () {
                var id = $(".layui-this").next().attr('lay-id');
                element.tabChange('itemTab', id);
            });
            // 分步表单上一步
            $(".upButton").on('click', function () {
                var id = $(".layui-this").prev().attr('lay-id');
                element.tabChange('itemTab', id);
            });
            $(".pic-delete").click(function (e) {
                    $(this).parent().parent().remove();
            });
            look_pic = function (pic) {
                console.log('111');
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: 0,
                    area: ['auto'],
                    skin: 'layui-layer-nobg', //没有背景色
                    shadeClose: true,
                    content: '<img src="' + pic + '" style="width:200px;" />'
                });
            };
            upload.render({
                elem: '#upload_img', url: "{:url('common/images')}", done: function (res) {
                    $("#img").val(res.data.name);
                    layer.msg(res.msg);
                }
            });

            tableSelect.render({
                elem: '#brand_select',
                checkedKey: 'id',
                searchKey: 'title',
                table: {
                    url: '/admin/goods.brand/list',
                    cols: [[
                        { type: 'radio' },
                        { field: 'id', title: 'ID' },
                        { field: 'title', title: '品牌' },
                    ]]
                },
                done: function (elem, data) {
                    var idArr = []
                    var title = []
                    layui.each(data.data, function (index, item) {
                        title.push(item.title)
                        idArr.push(item.id);
                    })
                    $("#brand_id").val(idArr.join(","));
            
                    $("#brand_select").val(title.join(","));
                }
            })

            tableSelect.render({
                elem: '#car_select',
                checkedKey: 'id',
                searchKey: 'title',
                table: {
                    url: '/admin/goods.car/list',
                    cols: [[
                        { type: 'radio' },
                        { field: 'id', title: 'ID' },
                        { field: 'title', title: '品牌' },
                    ]]
                },
                done: function (elem, data) {
                    var idArr = []
                    var title = []
                    layui.each(data.data, function (index, item) {
                        title.push(item.title)
                        idArr.push(item.id);
                    })
                    $("#car_id").val(idArr.join(","));
            
                    $("#car_select").val(title.join(","));
                }
            })

            tableSelect.render({
                elem: '#goods_type_select',
                checkedKey: 'id',
                searchKey: 'title',
                table: {
                    url: '/admin/goods.type/list',
                    cols: [[
                        { type: 'radio' },
                        { field: 'id', title: 'ID' },
                        { field: 'title', title: '类型' },
                    ]]
                },
                done: function (elem, data) {
                    var idArr = []
                    var title = []
                    layui.each(data.data, function (index, item) {
                        title.push(item.title)
                        idArr.push(item.id);
                    })
                    $("#goods_type_id").val(idArr.join(","));
            
                    $("#goods_type_select").val(title.join(","));
                }
            })

           

              // 上传商品图片
          
              var demoListView = $('#demoList'), uploadListIns = upload.render({
                elem: '#upload_pic'
                , url: "{:url('common/images')}"
                , accept: 'images'
                , multiple: true
                , auto: true
                //, bindAction: '#testListAction'
                , choose: function (obj) {
                    $("#img_list").show();
                    var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                    //读取本地文件
                    obj.preview(function (index, file, result) {
                        var tr = $(['<tr id="upload-' + index + '">'
                            , '<td><img src="' + result + '" style="width:28px;height:26px;" /></td>'
                            , '<td>' + (file.size / 1024).toFixed(1) + 'kb</td>'
                            , '<td>等待上传...</td>'
                            , '<td>'
                            , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                            , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                            , '</td>'
                            , '</tr>'].join(''));

                        //单个重传
                        tr.find('.demo-reload').on('click', function () {
                            obj.upload(index, file);
                            return false;
                        });

                        //删除
                        tr.find('.demo-delete').on('click', function () {
                            delete files[index]; //删除对应的文件
                            tr.remove();
                            uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                        });
                        demoListView.append(tr);
                    });

                    Sortable.create(
                        document.getElementById('demoList'),
                        { animation: 350 }
                    );
                }
                , done: function (res, index, upload) {
                    if (res.state == 1) { //上传成功
                        var tr = demoListView.find('tr#upload-' + index)
                            , tds = tr.children();
                        tds.eq(0).append('<input type="hidden" name="info[imgs][]" value="' + res.data.url + '" />');
                        tds.eq(2).html('<span style="color: #5FB878;">上传成功</img>');
                        return delete this.files[index]; //删除文件队列已经上传成功的文件
                    }
                    this.error(index, upload);
                }
                , error: function (index, upload) {
                    var tr = demoListView.find('tr#upload-' + index)
                        , tds = tr.children();
                    tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                    tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                }
            });

               // 上传商品图片
               var contentListView = $('#contentList'), uploadListIns = upload.render({
                elem: '#content_pic'
                , url: "{:url('common/images')}"
                , accept: 'images'
                , multiple: true
                , auto: true
                //, bindAction: '#testListAction'
                , choose: function (obj) {
                    $("#content_list").show();
                    var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                    //读取本地文件
                    obj.preview(function (index, file, result) {
                        var tr = $(['<tr id="upload-' + index + '">'
                            , '<td><img src="' + result + '" style="width:28px;height:26px;" /></td>'
                            , '<td>' + (file.size / 1024).toFixed(1) + 'kb</td>'
                            , '<td>等待上传...</td>'
                            , '<td>'
                            , '<button class="layui-btn layui-btn-xs content-reload layui-hide">重传</button>'
                            , '<button class="layui-btn layui-btn-xs layui-btn-danger content-delete">删除</button>'
                            , '</td>'
                            , '</tr>'].join(''));

                        //单个重传
                        tr.find('.content-reload').on('click', function () {
                            obj.upload(index, file);
                            return false;
                        });

                        //删除
                        tr.find('.content-delete').on('click', function () {
                            delete files[index]; //删除对应的文件
                            tr.remove();
                            uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                        });
                        contentListView.append(tr);
                    });

                    Sortable.create(
                        document.getElementById('contentList'),
                        { animation: 350 }
                    );
                }
                , done: function (res, index, upload) {
                    if (res.state == 1) { //上传成功
                        var tr = contentListView.find('tr#upload-' + index)
                            , tds = tr.children();
                        tds.eq(0).append('<input type="hidden" name="info[content][]" value="' + res.data.url + '" />');
                        tds.eq(2).html('<span style="color: #5FB878;">上传成功</img>');
                        return delete this.files[index]; //删除文件队列已经上传成功的文件
                    }
                    this.error(index, upload);
                }
                , error: function (index, upload) {
                    var tr = contentListView.find('tr#upload-' + index)
                        , tds = tr.children();
                    tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
                    tds.eq(3).find('.content-reload').removeClass('layui-hide'); //显示重传
                }
            });

                //新增属性分组
                $("#add_sku").click(function (e) {
                var dataId = (new Date()).getTime();
                var html = '<div class="layui-form-item">' +
                    '    <div class="layui-inline">' +
                    '        <label class="layui-form-label">分组名称</label>' +
                    '        <div class="layui-input-inline" style="width: 100px;">' +
                    '            <input type="text" name="sku[' + dataId + '][name]" data-id="' + dataId + '" autocomplete="off" class="group layui-input" placeholder="例：颜色">' +
                    '            <div class="layuimini-upload-btn delClassAttr" style="top:11px;right:8px;color:#C1C1C1;"><i class="fa fa-remove"></i></div>' +
                    '        </div>' +
                    '    </div>' +
                    '    <div class="layui-inline">' +
                    '        <label class="layui-form-label">属性规格</label>' +
                    '        <div class="layui-input-inline" style="width: 100px;">' +
                    '            <input type="text" name="sku[' + dataId + '][value][]" autocomplete="off" class="attr layui-input" placeholder="例：黑色">' +
                    '        </div>' +
                    '    </div>' +
                    '    <div class="layui-inline" id="button_' + dataId + '">' +
                    '        <div class="layui-input-inline">' +
                    '            <button type="button" data-id="' + dataId + '" class="addSkuRow layui-btn layui-btn-normal"><i class="fa fa-plus"></i> 新增</button>' +
                    '        </div>' +
                    '    </div>' +
                    '</div>';
                $("#sku_key").append(html);
                create_sku();
            });
               //新增属性规格
               $("body").on("click", ".addSkuRow", function () {
                var dataId = (new Date()).getTime();
               
                var html = '<div class="layui-inline">' +
                    '        <label class="layui-form-label">属性规格</label>' +
                    '        <div class="layui-input-inline" style="width: 100px;">' +
                    '            <input type="text" name="sku[' + dataId + '][value][]" data-id="' + dataId + '" autocomplete="off" class="attr layui-input group" placeholder="例：黑色">' +
                    '            <div class="layuimini-upload-btn delAttr" style="top:11px;right:8px;color:#C1C1C1;"><i class="fa fa-remove"></i></div>' +
                    '        </div>' +
                    '    </div>';
             
                // $("#button_" + dataId).before(html);
                $("#sku_sku_key").append(html);
                create_sku();
            });
          
            //实时生成sku
            var create_sku = function () {
                var group = new Array();
                $('.group').each(function () {
                    var dataId = $(this).attr('data-id');
                    if (dataId) group.push(dataId);
                });
                console.log(group);
                var attr = new Array();
                group.forEach((item, index) => {
                    attr[index] = new Array();
                    $('input[name="sku[' + item + '][value][]"]').each(function (i, element) {
                        attr[index][i] = $(this).val();
                    });
                });
        
                var allArr = cartesianProductOf(...attr);
                
                $("#sku_data").html("");
                attr.forEach((item, index) => {
                    // var groupName = item.toString().length <= 0 ? '默认' : item.toString();
                    var groupName = item.toString();
                    if(groupName){
                        var html = '' +
                        '<tr>' +
                        '   <td>' + groupName + '</td>' +
                        '   <td>' +
                        '       <input name="sku_data[' + index + '][sku_title]" value="' + groupName + '" type="hidden">' +
                        '       <input name="sku_data[' + index + '][money_cost]" type="number" style="display: unset;width: 80px;" autocomplete="off" class="money_cost layui-input"> 元' +
                        '   </td>' +
                        '   <td>' +
                        '       <input name="sku_data[' + index + '][money]" type="number" style="display: unset;width: 80px;" autocomplete="off" class="money layui-input"> 元' +
                        '   </td>' +
                        '   <td>' +
                        '       <input name="sku_data[' + index + '][stock]" type="number" style="display: unset;width: 80px;" autocomplete="off" class="stock layui-input"> ' +
                        '   </td>' +
                        '   <td style="text-align: center;"><input type="radio" name="is_default" value="xid_' + index + '" title="选择" ></td>' +
                        '   <td style="text-align: center;">' +
                        '       <button type="button" class="layui-btn layui-btn-xs layui-btn-danger delRuleRow">删除</button>' +
                        '   </td>' +
                        '</tr>';
                    }
                   
                    $("#sku_data").append(html);
                    form.render('radio');
                });


                // var group = new Array();
                // $('.group').each(function () {
                //     var dataId = $(this).attr('data-id');
                //      group.push(dataId);
                // });
                // // dataId = group;
                // console.log(group);
                // groupName =  $('input[name="sku[' + dataId + '][value][]"]').val();
                // var html = '' +
                //         '<tr>' +
                //         '   <td>' + groupName + '</td>' +
                //         '   <td>' +
                //         '       <input name="sku_data[' + dataId + '][sku_title]" value="' + groupName + '" type="hidden">' +
                //         '       <input name="sku_data[' + dataId + '][money_cost]" type="number" style="display: unset;width: 80px;" autocomplete="off" class="money_cost layui-input"> 元' +
                //         '   </td>' +
                //         '   <td>' +
                //         '       <input name="sku_data[' + dataId + '][money]" type="number" style="display: unset;width: 80px;" autocomplete="off" class="money layui-input"> 元' +
                //         '   </td>' +
                //         '   <td style="text-align: center;"><input type="radio" name="is_default" value="' + dataId + '" title="选择" ></td>' +
                //         '   <td style="text-align: center;">' +
                //         '       <button type="button" class="layui-btn layui-btn-xs layui-btn-danger delRuleRow">删除</button>' +
                //         '   </td>' +
                //         '</tr>';
                //     $("#sku_data").append(html);
                //     form.render('radio');
            

                
                // 删除一条sku分组
                $("body").on("click", ".delClassAttr", function () {
                    $(this).parent().parent().parent().remove();
                    create_sku();
                });

                // 删除一个属性
                $("body").on("click", ".delAttr", function () {
                    $(this).parent().parent().remove();
                    create_sku();
                });

                // 删除一条sku数据
                $("body").on("click", ".delRuleRow", function () {
                    if ($(this).parent().parent().parent().find('tr').length <= 1) return false;
                    $(this).parent().parent().remove();
                });
              

            }
            $("#saveButton").on('click', function () {
                var loading = layer.open({ type: 3 });
                var data = $("#DataForm").serialize()
                $.ajax({
                    url: "{:url('edit')}",
                    type: 'post',
                    data: data,
                    success: function (data) {
                        console.log(data);
                        layer.close(loading);
                        if (data.code == 0) {
                            parent.tableReload();
                            parent.layer.close(indexFrame);
                            parent.layer.msg(data.msg);
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                })
                return false;
            })
            // 生成规格
            function cartesianProductOf() {
                return Array.prototype.reduce.call(arguments, function (a, b) {
                    var ret = [];
                    a.forEach(function (a) {
                        b.forEach(function (b) {
                            ret.push(a.concat([b]));
                        });
                    });
                    return ret;
                }, [[]]);
            }
        });
    </script>
</body>

</html>